from ninja import Router, ModelSchema, Query, Field
from typing import List
from ninja.pagination import paginate
from utils.cj_crud import retrieve
from utils.cj_ninja import MyPagination, FuFilters
from system.models import LoginLog

router = Router()


class Filters(FuFilters):
    name: str = Field(None, alias="name")
    code: str = Field(None, alias="code")
    id: str = Field(None, alias="login_log_id")


class LoginOutSchemaOut(ModelSchema):
    class Config:
        model = LoginLog
        model_fields = "__all__"


@router.get("/login_log", response=List[LoginOutSchemaOut])
@paginate(MyPagination)
def list_login_log(request, filters: Filters = Query(...)):
    qs = retrieve(request, LoginLog, filters)
    return qs
